package com.github.prontera.config;

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

/**
 * 发送短信工具类
 * @author admin
 *
 */
public class SMSUtil {
	
	final static String url ="http://gw.api.taobao.com/router/rest";
	final static String appkey = "23553169";
	final static String secret = "f67a10e6293fb600ddd97550350671bd";
	
	/**
	 * 注册是发送验证码
	 * @param phone
	 * @param code
	 * @return
	 */
	public static boolean sendSMS(String phone,String code){
		try{
			TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
			AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
			req.setExtend("123456");
			req.setSmsType("normal");
			req.setSmsFreeSignName("易路领鲜");
			req.setSmsParamString("{\"val_code\":\""+code+"\"}");
			req.setRecNum(phone);
			req.setSmsTemplateCode("SMS_16725327");
			AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
			System.out.println(phone+"  :   "+ code  +"发送结果为 ======      "+ rsp.getBody());
		}catch(Exception e){
			e.printStackTrace();
			
			return false;
		}
		
		return true;
	}
	
	/**
	 * 发送验证码
	 * @param phone
	 * @param code
	 * @return
	 */
	public static boolean sendCode(String phone,String code){
		try{
			TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
			AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
			req.setExtend("123456");
			req.setSmsType("normal");
			req.setSmsFreeSignName("快播");
			req.setSmsParamString("{\"code\":\""+code+"\"}");
			req.setRecNum(phone);
			req.setSmsTemplateCode("SMS_16800425");
			AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
			System.out.println(phone+"  :   "+ code  +"发送结果为 ======      "+ rsp.getBody());
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		sendSMS("15736882798","擦浪嘿！");
	}

	
	
	
}
